/** 
 * NumericExpression.java
 * @author Lex
 * 2007-8-20 ����03:30:26
 */
package fun.parser.ast.node;

import fun.parser.EvaluationException;
import fun.parser.ast.node.base.Expression;
import fun.parser.lexer.Token;
import fun.parser.lexer.TokenType;
import fun.symtable.SymbolTable;

/**
 * 
 */
public class NumericExpression extends Expression {
    private double value = 0;

    public NumericExpression(Token token) {
	super(token);
	if (TokenType.REAL == token.getTokenType()) {
	    value = Double.valueOf(token.getImage());
	} else {
	    int radix = 10;
	    switch (token.getTokenType()) {
	    case BINARY:
		radix = 2;
		break;
	    case OCTAL:
		radix = 8;
		break;
	    case DECIMAL:
		radix = 10;
		break;
	    case HEXADECIMAL:
		radix = 16;
		break;
	    }
	    value = Integer.valueOf(token.getImage(), radix);
	}
    }

    @Override
    public double getValue(SymbolTable symtable) throws EvaluationException {
	return value;
    }
}
